<template>
  <div class="login-container">
    <van-form @submit="onSubmit" class="login-form">
      <van-cell-group inset>
        <van-field
          v-model="username"
          name="username"
          label="用户名"
          placeholder="请输入用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          placeholder="请输入密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
      </van-cell-group>

      <div class="submit-btn-wrapper">
        <van-button round block type="primary" native-type="submit">
          登录
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { showToast } from 'vant'
import { useRouter } from 'vue-router'

const router = useRouter()
const username = ref('admin')
const password = ref('123456')

const onSubmit = (values) => {
  // 验证用户名和密码
  if (values.username === 'admin' && values.password === '123456') {
    showToast('登录成功')
    // 登录成功后跳转到首页
    router.push('/home')
  } else {
    showToast('用户名或密码错误')
  }
}
</script>

<style scoped>
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

.login-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f7f8fa;
  overflow: hidden;
  margin: 0;
  padding: 0;
  height: 100%;
  box-sizing: border-box;
}

.login-form {
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  max-width: 600px;
}

.submit-btn-wrapper {
  margin: 16px 0;
}

:deep(.van-cell-group) {
  margin-bottom: 16px;
}

:deep(.van-field__label) {
  width: 4em;
}
</style> 